<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.pay.bean.GlobalData" %>
<%@ page import="com.pay.bean.PayResultBean" %>
<%@ page import="com.pay.util.MD5" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.InputStreamReader" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/1/12 0012
  Time: 上午 9:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
    System.out.println("noteResult");
    BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
    StringBuffer buffer = new StringBuffer();
    String temp;
    while ((temp = reader.readLine()) != null) {
        buffer.append(temp);
    }
    reader.close();
    String input = buffer.toString();
    if (null != input && 0 != input.length()) {
        System.out.println("noteResult data = " + input);
        PayResultBean payResultBean = JSONObject.parseObject(input, PayResultBean.class);
        if (null != payResultBean) {
            String md5 = MD5.getMD5(GlobalData.composePayResultJsonStr(payResultBean));
            if (payResultBean.getSgn().equals(md5)) {
                if (GlobalData.STATE_SUCCESS.equals(payResultBean.getState())) {
                    System.out.println(GlobalData.STATE_SUCCESS);
                    response.getWriter().write(GlobalData.STATE_SUCCESS);
                } else {
                    response.getWriter().print(GlobalData.STATE_SIGN_NOT_PASSED);
                }
                return;
            }
        }
        System.out.println(GlobalData.STATE_FAILED);
        response.getWriter().write(GlobalData.STATE_FAILED);
        return;
    }
    System.out.println(GlobalData.STATE_EMPTY_JSON);
    response.getWriter().print(GlobalData.STATE_EMPTY_JSON);
%>
